package py.progweb.sgc.gui.client.dialog;

import java.util.List;

import py.progweb.sgc.gui.client.service.ABMService;
import py.progweb.sgc.gui.client.service.ABMServiceAsync;
import py.progweb.sgc.gui.client.service.DialogModelService;
import py.progweb.sgc.gui.client.service.DialogModelServiceAsync;
import py.progweb.sgc.gui.client.widget.TablaFiltro;
import py.progweb.sgc.gui.client.widget.ToolbarListener;
import py.progweb.sgc.gui.shared.dialogmodel.DataRecord;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;

public abstract class ListadoBase extends VentanaBase implements ToolbarListener {

	TablaFiltro tabla;
	DialogModelServiceAsync service;
	ABMServiceAsync abmService;
	
	public ListadoBase(String titulo) {
		super(titulo);
		
		abmService = GWT.create(ABMService.class);
		service = GWT.create(DialogModelService.class);
	}	
	
	@Override
	public void eliminar() {
		List<DataRecord> items = tabla.getFilasSeleccionadas();
		
		abmService.borrar(items, new AsyncCallback<Void>() {
			
			@Override
			public void onSuccess(Void result) {
				Window.alert("Los items han sido borrados");
				reset();
			}
			
			@Override
			public void onFailure(Throwable caught) {
				//manejarError(caught);
				Window.alert(caught.getLocalizedMessage());
				if (caught.getCause() != null){
					Window.alert("Hola");
					Window.alert(caught.getCause().toString());
				}
			}
		});
	}
}
